#include<iostream>
using namespace std;
#include<stack>
#include<cstring>
int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		string str;
		cin >> str;
		stack<char> s;
		int k = 1;
		for (char ch : str) {
			if (ch == '{' || ch == '[' || ch == '(') {
				s.push(ch);
			}
			if (ch == '}' || ch == ')' || ch == ']') {
				if (s.empty()) {
					k = 0;
					break;
				}
				char c = s.top();
				s.pop();
				if (c == '{' && ch != '}' || c == '(' && ch != ')' || c == '[' && ch != ']') {
					k = 0;
					break;
				}
			}
		}
		if (s.empty() && k) {
			cout << "ok" << endl;
		}
		else {
			cout << "error" << endl;
		}
	}
	return 0;
}